"""
作者：Leagolas
日期：2023年06月09日
"""


#该py文件用于随机生成点单信息
import pymysql
from datetime import datetime
import random

def generateRecords():
    connection = pymysql.connect(host='localhost', user='root', password=' ', database='milkteashop')
    cursor = connection.cursor()

    scList = ['SC1011', 'SC1012', 'SC1013', 'SC1021', 'SC1022', 'SC1023', 'SC1031', 'SC1032', 'SC1033', 'SC1041',
              'SC1042', 'SC1043', 'SC1051', 'SC1052', 'SC1053', 'SC1061', 'SC1062', 'SC1063', 'SC2011', 'SC2012',
              'SC2013', 'SC2021', 'SC2022', 'SC2023', 'SC3011', 'SC3012', 'SC3021', 'SC3022'];
    ingList = ['RM1001', 'RM1002', 'RM1003', 'RM1004', 'RM1005', 'RM1006', 'RM1007', 'RM1008', 'RM1009', 'RM1010',
               'RM1011', 'RM1012']
    newDate = int(datetime.now().strftime('%d'))
    for date in range(newDate):
        date = "2023-6-" + str(date + 1).zfill(2)
        dailySale = int(random.uniform(100, 300))
        for i in range(dailySale):
            i = i + 1
            serial_number = 'S' + str(i).zfill(5)
            s_c_id = random.choice(scList)
            cursor.execute("INSERT INTO sale_records VALUES ('%s', '%s','%s',1);" % (date, serial_number, s_c_id))
            connection.commit()
            if (random.random() >= 0.5):
                ingNum = random.randint(1, 2)
                if ingNum > 0:
                    ingIndexes = random.sample(range(12), ingNum)
                    for index in ingIndexes:
                        cursor.execute("INSERT INTO sale_records VALUES ('%s', '%s','%s',1);" % (
                        date, serial_number, ingList[index]))
                        connection.commit()
    print("随机购买记录生成成功!!!")

generateRecords()





